package yunhe.test;



import javax.swing.JButton;
import javax.swing.JFrame;

import yunhe.control.Controlller;
import yunhe.entity.Food;
import yunhe.entity.Ground;
import yunhe.entity.Snake;
import yunhe.view.GamePanel;

public class SnakeGameStart {

	public static void main(String[] args) {
		
		// 实体对象的创建
		
		Snake snake = new Snake();
		Food food = new Food();
		Ground ground = new Ground();
		
		// 视图对象的创建
		GamePanel gamePanel = new GamePanel();
		//控制器的创建
		Controlller controlller=new Controlller(snake,food,ground,gamePanel);
		//给蛇添加监听器
		snake.addSnakeListener(controlller);
		//给面板事件添加监听器
		gamePanel.addKeyListener(controlller);
		//窗体标题
		JFrame frame=new JFrame("贪吃蛇_liuliudahuan_1.0");
		//设置窗体大小
		frame.setSize(350, 350);
		//设置窗体关闭的时候自动退出
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//设置窗口位于屏幕中央
		frame.setLocationRelativeTo(null);
		//让那个面板获得焦点
		gamePanel.setFocusable(true);
		//添加面板
		frame.add(gamePanel);
		//启动游戏
		controlller.startGame();
		//显示
		frame.setVisible(true);
	
	}	
}
